package com.system.FinancialDepartment.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.FinancialDepartment.dao.RewardAndPunishimentRepository;
import com.system.FinancialDepartment.entity.RewardAndPunishiment;


@Service
@Transactional
public class RewardAndPunishimentService implements IRewardAndPunishimentService{

	@Autowired
	private RewardAndPunishimentRepository rapRepository;
	
	@Override
	public void saveOrUpdate(RewardAndPunishiment rewardAndPunishiment) {
		if(null!=rewardAndPunishiment.getId()) {
			rapRepository.updateRewardAndPunishiment(rewardAndPunishiment.getId(),rewardAndPunishiment.getEmpId(),rewardAndPunishiment.getEvent(),rewardAndPunishiment.getTime(),rewardAndPunishiment.getScore());
		}else {
			rapRepository.save(rewardAndPunishiment);
		}
	}

	@Override
	public void delete(RewardAndPunishiment rewardAndPunishiment) {
		rapRepository.delete(rewardAndPunishiment);
		
	}

	@Override
	public RewardAndPunishiment findOne(Long id) {
		return rapRepository.findById(id);
	}

	@Override
	public List<RewardAndPunishiment> findAll() {
		return (List<RewardAndPunishiment>) rapRepository.findAll();
	}

	@Override
	public int saveOrUpdate(Long id,Long empId,String event, Date time, Long score) {
		return rapRepository.updateRewardAndPunishiment(id,empId,event, time, score);
	}

	@Override
	public int deleteRewardAndPunishiments(Long[] ids) {
		return rapRepository.deleteRewardAndPunishiments(ids);
	}
	
	public Page<RewardAndPunishiment> findAll(Long empId,Pageable pageable){
		return rapRepository.findAll(empId, pageable);
	}

	@Override
	public List<RewardAndPunishiment> findAllById(Long empId) {
		
		return rapRepository.findAll(empId);
	}
	

}
